﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="locate.aspx.cs" Inherits="wechat_locate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>爱尚洗车</title>
    <link href="styles/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="styles/weui.css" rel="stylesheet" type="text/css" />
    <link href="styles/NewGlobal.css" rel="stylesheet" type="text/css" />
    <link href="styles/map.css" rel="stylesheet" type="text/css" />
    <script src="scripts/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="scripts/jquery.query-2.1.7.js" type="text/javascript"></script>
    <script src="scripts/jquery.cookie.js" type="text/javascript"></script>
    <script src="scripts/common.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js "></script>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=14840981ab05a0c59cd312c31554a841&plugin=AMap.Geocoder"></script>
    <script src="js/location.js" type="text/javascript"></script>
    <style type="text/css">
        .amap-container { cursor: url(http://webapi.amap.com/theme/v1.3/openhand.cur),default; }
        .amap-drag { cursor: url(http://webapi.amap.com/theme/v1.3/closedhand.cur),default; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="map">
        <div class="header">
            <div class="top-name">
                <p>
                    车辆位置</p>
            </div>
            <a class="nav-back" href="#" onclick="select_ok()"><span>确定</span></a>
        </div>
        <div id="mapcenter">
        </div>
        <div id="maplocation">
        </div>
        <div id="mapmarker">
            <img src="images/mapmarker.png"></div>
    </div>
    <script type="text/javascript">
        $("#mapcenter").height($(window.document).height() - 50);
        init_map(0,0);
        //loadMap('', '');
        $(function () {
            wx.ready(function () {
                wx.getLocation({
                    type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                    success: function (res) {
                        var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                        var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                        var speed = res.speed; // 速度，以米/每秒计
                        var accuracy = res.accuracy; // 位置精度
                        alert(latitude); alert(longitude);
                        loadMap(longitude, latitude);
                    },
                    cancel: function (res) {
                        var citysearch = new AMap.CitySearch();
                        //自动获取用户IP，返回当前城市
                        citysearch.getLocalCity(function (status, result) {
                            if (status === 'complete' && result.info === 'OK') {
                                if (result && result.city && result.bounds) {
                                    var cityinfo = result.city;
                                    var citybounds = result.bounds;
                                }
                            }
                            else {
                                //document.getElementById('tip').innerHTML = result.info;
                            }
                        });
                    }
                });
            });
        });
        var map, marker;
        function loadMap(lng, lat) {
            if (lng != '' && lat != '') {
                map = new AMap.Map('mapcenter', {
                    resizeEnable: true,
                    zoom: 15,
                    center: [lng, lat]
                });
            }
            else {
                map = new AMap.Map('mapcenter', {
                    resizeEnable: true,
                    zoom: 15
                });
            }
            map.on('complete', function () {
                var center = map.getCenter();
                addPoint(center.lng, center.lat);
            });
            map.on('mapmove', function () {
                //var center = map.getCenter();
                //                marker.setPosition(112.45404, 34.619683);
                //                regeocoder();
            });
        }

        function addPoint(lng, lat) {
            marker = new AMap.Marker({
                map: map,
                position: [lng, lat],
                draggable: true,
                cursor: 'move',
                raiseOnDrag: false,
                topWhenMouseOver: true
            });
            regeocoder();
        }

        function regeocoder() {  //逆地理编码
            var geocoder = new AMap.Geocoder({
                radius: 1000,
                extensions: "all"
            });
            geocoder.getAddress(marker.getPosition(), function (status, result) {
                if (status === 'complete' && result.info === 'OK') {
                    geocoder_CallBack(result);
                }
            });
        }
        function geocoder_CallBack(data) {
            var address = data.regeocode.formattedAddress; //返回地址描述
            var infoWindow = new AMap.InfoWindow({
                isCustom: true,
                offset: new AMap.Pixel(0, -35)
            });
            $('#maplocation').html(address);
        }
    </script>
    </form>
</body>
</html>
